﻿#include <iostream>
#include <boost/asio.hpp>

int main() {
	try {
		boost::asio::io_context ioc;
		boost::asio::ip::tcp::endpoint ep(boost::asio::ip::make_address("127.0.0.1"), 3333);
		boost::asio::ip::tcp::socket sock(ioc);
		boost::system::error_code ec;
		sock.connect(ep, ec);
		if (ec) {
			std::cout << "connect failed error code is " << ec.value() 
				<< " error message is " << ec.message() << std::endl;
		}
		char arr[1024];
		while (1) {
			std::string send_message = "hello server";
			size_t size = sock.send(boost::asio::buffer(send_message.c_str(), send_message.size()));
			sock.receive(boost::asio::buffer(arr, size));
			std::cout <<"recieve server message is" << std::string(arr, size) << std::endl;
			getchar();
		}
	}
	catch (boost::system::error_code& e) {
		std::cout << "Error value is " << e.value() << " message is " << e.message() << std::endl;
	}

	return 0;
}